package com.example;

import com.example.utils.ConnectionFactoryUtils;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

/**
 * @author wangxiyuan
 * @description
 * @createDate 2021/3/26 19:20
 **/
public class DeadLetterProducer {
    public static void main(String[] args) throws Exception {
        //2 获取Connection
        Connection connection = ConnectionFactoryUtils.getConnection();
        //3 通过Connection创建一个新的Channel
        Channel channel = connection.createChannel();

        String exchange = "test_dlx_exchange";
        String routingKey = "dlx.save";

        String msg = "Hello RabbitMQ DLX Message";

        AMQP.BasicProperties properties = new AMQP.BasicProperties.Builder()
                .deliveryMode(2)
                .contentEncoding("UTF-8")
                .expiration("5000")
                .build();
        //发送消息
        channel.basicPublish(exchange, routingKey, true, properties, msg.getBytes());
    }
}
